package org.zizi.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.jasper.runtime.HttpJspBase;
import org.zizi.manager.Managers;
import org.zizi.manager.impl.DaoManager;

/**
 * 处理从页面来的请求
 * 	
 * 	开启事务，让页面更方便的访问数据库
 * 
 * @author zizi
 *
 */
public abstract class JspPageServlet extends HttpJspBase
{
	private static final long serialVersionUID = 1L;

	public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException
	{
		DaoManager dm = Managers.get(DaoManager.class);
		try
		{
			dm.begin();
			
			super.service(req, resp);
			
			dm.commit();
		}
		catch (Exception e) 
		{
			throw new ServletException(e);
		}
		finally
		{
			dm.end();
		}
	}
}
